package com.example.klinedemo

import android.content.Context
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.example.klinedemo.bean.DataResult
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

class MainActivityViewModel:ViewModel() {

    private val netWork = NetWork()

    public val liveData = MutableLiveData<DataResult>()


    public fun initData(context: Context) {
        viewModelScope.launch {
            val kLineData = withContext(Dispatchers.IO){
                netWork.getKLineData(context)
            }
            liveData.value = kLineData
        }
    }
}